package cn.ly.security.controller;

import cn.ly.security.entity.Dynamic;
import cn.ly.security.service.impl.DynamicServiceImpl;
import cn.ly.security.util.DataPojo;
import cn.ly.security.util.Pagely;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.LinkedList;

@RestController
@RequestMapping("/Dynamic")
@Api(tags="修改动态")
@CrossOrigin("*")
public class DynamicController {
    @Autowired
    DynamicServiceImpl dynamicService;

    @GetMapping("/selectAll")
    public DataPojo selectAll(Pagely pagely){
        Page<Dynamic> page = dynamicService.page(new Page<>(pagely.getCurrent(),pagely.getSize()));
        ArrayList<Object> objects = new ArrayList<>();
        objects.add(page);
        return new DataPojo("200","无异常",objects);
    }

    @PutMapping("/insertDynamic")
    public DataPojo insertDynamic(Dynamic dynamic){
        boolean save = dynamicService.save(dynamic);
        ArrayList<Object> objects = new ArrayList<>();
        objects.add(save);
        return new DataPojo("200","无异常",objects);
    }

    @DeleteMapping("/deleteDynamicByPrimaryKey")
    public DataPojo deleteDynamicByPrimaryKey(Integer id){
        boolean b = dynamicService.removeById(id);
        ArrayList<Object> objects = new ArrayList<>();
        objects.add(b);
        return new DataPojo("200","无异常",objects);
    }

    @PostMapping("/updateDynamic")
    public DataPojo updateDynamic(Dynamic dynamic){
        boolean save = dynamicService.updateById(dynamic);
        ArrayList<Object> objects = new ArrayList<>();
        objects.add(save);
        return new DataPojo("200","无异常",objects);
    }
}
